﻿<navigation:Page x:Class="RIA.NTiersApp.Views.CustomerList" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="CustomerList Page"
                 xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" 
                 xmlns:my="clr-namespace:RIA.DAL;assembly=RIA.ServicesLibrary" 
                 xmlns:my1="clr-namespace:RIA.ServicesLibrary.Web.Services;assembly=RIA.ServicesLibrary" 
                 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                 xmlns:vm="clr-namespace:RIA.ViewModel;assembly=RIA.ViewModel"
                 xmlns:local="clr-namespace:RIA.NTiersApp.Controls"
                 xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    <navigation:Page.DataContext>
        <vm:CustomerListViewModel />
    </navigation:Page.DataContext>
    <Grid x:Name="LayoutRoot" >
        <Grid.RowDefinitions>
            <RowDefinition Height="64" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" ></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Height="30" HorizontalAlignment="Left" Margin="5" Name="stackPanel1" 
                    VerticalAlignment="Top" 
                    Orientation="Horizontal"
                    >
            <TextBlock x:Name="lblName" Text="Customer name:"  VerticalAlignment="Center"></TextBlock>
            <TextBox x:Name="txtName"  Width="150" Text="{Binding Path=FirstName, Mode=TwoWay}"></TextBox>
            <Button x:Name="btnSearch" 
                    Content="Search"
                    Command="{Binding Path=LoadPagedCustomers}" 
                    CommandParameter="{Binding ElementName=txtName, Path=Text}" 
                    ></Button>
        </StackPanel>
        <toolkit:BusyIndicator Grid.Row="1" Name="busyIndicator1"  IsBusy="{Binding IsBusy}"  BusyContent="Loading...">
            <StackPanel >
                <Button x:Name="btnAdd" Content="Add New"  Width="100" HorizontalAlignment="Right" Margin="5" Click="btnAdd_Click"></Button>
                <sdk:DataGrid AutoGenerateColumns="False" 
                      Margin="5" 
                      Name="customerDataGrid"
                      RowDetailsVisibilityMode="VisibleWhenSelected"
                      VerticalAlignment="Top"  
                                               
                      ItemsSource="{Binding Path=DataList}" IsReadOnly="False">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn x:Name="companyNameColumn" Binding="{Binding Path=CompanyName}" Header="Company Name" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="emailAddressColumn" Binding="{Binding Path=EmailAddress}" Header="Email Address" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="firstNameColumn" Binding="{Binding Path=FirstName}" Header="First Name" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="lastNameColumn" Binding="{Binding Path=LastName}" Header="Last Name" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="middleNameColumn" Binding="{Binding Path=MiddleName}" Header="Middle Name" Width="SizeToHeader" />
                        <sdk:DataGridTemplateColumn x:Name="modifiedDateColumn" Header="Modified Date" Width="SizeToHeader">
                            <sdk:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <sdk:DatePicker SelectedDate="{Binding Path=ModifiedDate, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellEditingTemplate>
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=ModifiedDate, StringFormat=\{0:d\}}" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridCheckBoxColumn x:Name="nameStyleColumn" Binding="{Binding Path=NameStyle}" Header="Name Style" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="phoneColumn" Binding="{Binding Path=Phone}" Header="Phone" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="salesPersonColumn" Binding="{Binding Path=SalesPerson}" Header="Sales Person" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="suffixColumn" Binding="{Binding Path=Suffix}" Header="Suffix" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="titleColumn" Binding="{Binding Path=Title}" Header="Title" Width="SizeToHeader" />
                        <sdk:DataGridTemplateColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" >
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <HyperlinkButton Content="details" Tag="{Binding}" Click="NameButton_Click" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </StackPanel>
            
         </toolkit:BusyIndicator>
        <sdk:DataPager Grid.Row="2" Height="25" Margin="5" Name="dataPager1" PageSize="{Binding PageSize}" Width="200" Source="{Binding Path=DataList}" />
    </Grid>
</navigation:Page>
